<template>
  <div class="app-container">
    <!--搜索框-->
<el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="挂号单ID" prop="ghdh">
        <el-input
          v-model="queryParams.ghdh"
          placeholder="请输入挂号单号"
          clearable
          size="small"
          style="width: 300px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="患者姓名" prop="hz_name">
        <el-input
          v-model="queryParams.hz_name"
          placeholder="请输入患者姓名"
          clearable
          size="small"
          style="width: 300px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
      </el-form-item>
    </el-form>
<!--表格数据-->
    <el-card class="box-card" >
      <el-table v-loading="loading" :data="postList" >
        <el-table-column type="selection" width="55" align="center" :selectable="checkSelect"/>
        <el-table-column label="订单号" align="center" prop="ddh" />
        <el-table-column label="挂号单号" align="center" prop="ghdh" />
        <el-table-column label="患者姓名" align="center" prop="hz_name" />
        <el-table-column label="总金额" align="center" prop="z_money" />
        <el-table-column label="支付类型" align="center" prop="zf_type"  />
        <el-table-column label="订单状态" align="center" prop="status"  />
        <el-table-column label="创建时间" align="center" prop="createTime" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button type="success">详情</el-button>
            <el-button type="danger"
                       @click="handleDelete(scope.row)"
                       :disabled="multiple"
                       v-hasPermi="['sfgl_lgl:search:refund']">退费</el-button>
          </template>
        </el-table-column>
      </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    </el-card>
  </div>
</template>

<script>
import { listSfTable,refund } from "@/api/sfgl_lgl/chuFang";

export default {
  name: "index",
  data() {
    return {
      // 遮罩层
      loading: true,

      // 非多个禁用
      multiple: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单表格数据
      postList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 状态数据字典
      statusOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        postCode: undefined,
        postName: undefined,
        status: undefined
      },
      // 表单参数
      form: {},

    };
  },
  mounted: function () {     //页面加载完成后执行的方法

  },
  created() {
    this.getList();
    this.getDicts("sys_normal_disable").then(response => {
      this.statusOptions = response.data;
    });
  },
  methods: {
    /** 动态分页查询订单信息 */
    getList() {
      listSfTable(this.queryParams).then(response => {
        this.postList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 岗位状态字典翻译
    statusFormat(row, column) {
      return this.selectDictLabel(this.statusOptions, row.status);
    },


    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 退费按钮操作 */
    handleDelete(row) {
      const ddh = row.ddh;
      const dd_status = row.status;
      console.log(dd_status);
      if(dd_status=="支付成功"){
        console.log(ddh);
        this.$confirm('是否要为订单编号为"' + ddh + '"的数据项退费', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return refund({'ddh':ddh});
        }).then(() => {
          this.getList();
          this.msgSuccess("退费成功");
        })
      }else{
        console.log("还没交钱,点我干啥");
      }
    },
    //检查行是否可选
    checkSelect(row,index) {
      if (row.status =="已退费") { // 判断里面是否存在某个参数
        this.multiple=true
      } else {
        this.multiple=false
      }
    }


  }
};
</script>
